<?php
//include_once dirname(__FILE__).'/_config.php';
//if(isset($T)){
	
	include_once APP_PTH.'./_tpl.php';
	set_template_path($T, $__tpl_pth);

	$vars['_tpl'] = $__tpl;
	$vars['_act'] = array(
		'frm'		=> $__frm,
		'mdl'		=> $__mdl,
		'do'		=> $__do,
	);
	// 搜索参数
	if(!empty($_GET)){
		unset($_GET['page']);
		foreach ($_GET as $key => $val){
			if(is_array($val))unset($_GET[$key]);
			continue;
			if(MAGIC_QUOTE)$_GET[$key] = stripslashes($val);
		}
		array_map('urlencode', $_GET);
	}
	$vars['get'] = $_GET;
	
	// 为调试服务
	$myurl = array_shift(explode('&__debug__', CUR_URL));
	if(strpos($myurl, '?') === false){
		$myurl .= '?dbg&__debug__';
	}else{
		$myurl .= '&__debug__';
	}
	
	$vars['_s'] = array(
		#'web_pth'		=> WEB_PTH,
		#'inc_pth'		=> INC_PTH,
		#'lib_pth'		=> LIB_DIR,
		#'plg_pth'		=> PLG_PTH,
		#'thr_pth'		=> THR_PTH,											// 主题根路径
		#'theme_pth'	=> empty($__theme_pth)	? THR_PTH : $__theme_pth,	// 当前主题路径
		
		'web_dir'		=> WEB_DIR,
		'app_dir'		=> APP_DIR,
		'lib_dir'		=> LIB_DIR,
		'plg_dir'		=> PLG_DIR,
		'thr_dir'		=> THR_DIR,											// 主题根目录
		'theme_dir'		=> empty($__theme_dir)	? THR_PTH : $__theme_dir,	// 当前主题目录
		
		'lang_dir'		=> $__lang_dir,
		'js_dir'		=> JS_DIR,
		'img_dir'		=> IMG_DIR,
		'swf_dir'		=> SWF_DIR,
		'up_dir'		=> UP_DIR,
		'pub_dir'		=> PUB_DIR,
		
		'cache_dir'		=> CAC_DIR,
		'cookie_pre'	=> COOKIE_PRE,
		
		'pub_url'		=> WEB_URL.'pub/',
		'web_url'		=> WEB_URL,
		'up_url'		=> UP_URL,											// 上传文件的WEB访问路径
		'myurl'			=> $myurl,
		'referrer'		=> REF_URL,

		'DEBUG_PR'		=> defined('DEBUG_PR') && DEBUG_PR == true ? 1 : 0,
		'DEBUG_FB'		=> defined('DEBUG_FB') && DEBUG_FB == true ? 1 : 0,
		'DEBUG_XHPROF'	=> defined('DEBUG_XHPROF') && DEBUG_XHPROF == true ? 1 : 0,
	);

	$vars['_econfig'] = $__f_econfig;
	$vars['_sysvars'] = $__f_sysvars;	// 商店设置相关信息
	
	if(defined('DEBUG_PR') && DEBUG_PR == true){

		if(isset($_GET['server']) && $_GET['server'] == 'yes'){
			$GLOBALS['debug_info'][] = anchor('server');
			$GLOBALS['debug_info']['_SERVER'] = $_SERVER;
		}

		if(!empty($_GET['vars']) && $_GET['vars'] == 'yes'){				// 打印所有模板变量
			$GLOBALS['debug_info'][] = anchor('vars');
			$GLOBALS['debug_info']['vars'] = $vars;
		}

		if(isset($_GET['funcs']) && $_GET['funcs'] == 'yes'){
			$GLOBALS['debug_info'][] = anchor('funcs');
			$GLOBALS['debug_info']['funcs'] = Trace::get_user_funcs();
		}

		if(isset($_GET['lang']) && $_GET['lang'] == 'yes'){
			$GLOBALS['debug_info'][] = anchor('lang');
			$GLOBALS['debug_info']['language_pack'] = $__l;
		}

		if(isset($_GET['classes']) && $_GET['classes'] == 'yes'){
			$GLOBALS['debug_info'][] = anchor('classes');
			$GLOBALS['debug_info']['classes'] = Trace::get_user_classes();
		}

		if(!empty($_GET['cls'])){
			$GLOBALS['debug_info']['cls'] = Trace::get_class_info($_GET['cls']);
			if(!empty($_GET['method'])){
				$GLOBALS['debug_info']['method'] = Trace::get_method_info($_GET['cls'], $_GET['method']);
			}
		}

		if(isset($_GET['exts']) && $_GET['exts'] == 'yes'){
			$GLOBALS['debug_info'][] = anchor('exts');
			$GLOBALS['debug_info']['exts'] = Trace::get_extension_loaded();
		}

		if(!empty($_GET['ext'])){
			$GLOBALS['debug_info']['ext'] = Trace::get_extension_info($_GET['ext']);
		}
		
		if(!empty($_GET['fn'])){
			$GLOBALS['debug_info']['fn'] = Trace::get_func_info($_GET['fn']);
		}

		$GLOBALS['debug_info']['runtime'] = $GLOBALS['runtime'];

		if(isset($GLOBALS['debug_info'])){
			$GLOBALS['debug_info']['syspath'] = $vars['_s'];
			$vars['debug_info'] = anchor('debug_info', "调试信息：<br />\n").print_r($GLOBALS['debug_info'], true);
		}
	}
	
	if(defined('DEBUG_FB') && DEBUG_FB == true){
		@fb(error_get_last(), 'err');
		FB::trace('_flush.php');

		if(isset($_GET['lang']) && $_GET['lang'] == 'yes'){
			fb($__l, 'language_pack');
		}

		if(isset($_GET['classes']) && $_GET['classes'] == 'yes'){
			fb(Trace::get_user_classes(), 'classes');
		}

		if(!empty($_GET['cls'])){
			fb(Trace::get_class_info($_GET['cls']), 'cls');
			if(!empty($_GET['method'])){
				fb(Trace::get_method_info($_GET['cls'], $_GET['method']), 'method');
			}
		}

		if(isset($_GET['exts']) && $_GET['exts'] == 'yes'){
			fb(Trace::get_extension_loaded(), 'exts');
		}

		if(!empty($_GET['ext'])){
			fb(Trace::get_extension_info($_GET['ext']), 'ext');
		}
		
		if(!empty($_GET['fn'])){
			fb(Trace::get_func_info($_GET['fn']), 'fn');
		}

		fb($GLOBALS['runtime'], 'runtime');
	}
	
	if(defined('DEBUG_XHPROF') && DEBUG_XHPROF == true){
		$xhprof_data = xhprof_disable();
			
		include_once $_SERVER['DOCUMENT_ROOT'].'/../xhprof_lib/utils/xhprof_lib.php';
		include_once $_SERVER['DOCUMENT_ROOT'].'/../xhprof_lib/utils/xhprof_runs.php';
	
		$xhprof_runs = new XHProfRuns_Default();
		$run_id = $xhprof_runs->save_run($xhprof_data, 'xhprof_trace');
	
		$vars['xhprof_run_id'] = $run_id;
	}

	if(isset($vars))$T->assign($vars);

	echo $html_data = $T->fetch($__tpl['file'], null, null, false);

	/*******************************************************************************
	 * 生成静态文件（就放这，虽然后台没有生成静态文件的需要）
	 * 不生成文件就是伪静态，呵呵
	 *******************************************************************************/
	if($__f_sysvars['url_rewrite'] == 'html' 
		&& isset($_GET['mk']) && $_GET['mk'] == 'yes' && !empty($__filename) && !empty($html_data)){
		try{
			File::makeHtml($__filename, $html_data);
			/* if(!empty($__fileindex)){
				File::makeHtml($__fileindex, $html_data);
			} */
		}catch(Exception $e){exit();}
	}
//}



?>